package com.golden.procedure;

import org.activiti.engine.impl.persistence.entity.data.impl.MybatisGroupDataManager;
import org.activiti.engine.impl.persistence.entity.data.impl.MybatisUserDataManager;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.SecurityAutoConfiguration;

/**
* <b>Description:</b><br> 
* @author Reading.Reagan</a>
* @version 1.0
* @Note
* <b>ProjectName:</b> setting
* <br><b>PackageName:</b> com.golden.setting.controller
* <br><b>ClassName:</b> package-info
* <br><b>Date:</b> 2018年9月18日 上午9:13:02
*/

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.provisioning.JdbcUserDetailsManager;

import com.golden.procedure.config.SpringSecurityGroupManager;
import com.golden.procedure.config.SpringSecurityUserManager;

@EnableDiscoveryClient
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@ComponentScan
@EnableFeignClients
@MapperScan({ "com.golden.procedure.dao" })
public class ProcedureApplication {

	public static void main(String[] args) {
		SpringApplication.run(ProcedureApplication.class, args);
	}

	@Autowired
	private SpringProcessEngineConfiguration processEngineConfiguration;

	@Autowired
	private JdbcUserDetailsManager userManager;

	@Bean
	InitializingBean processEngineInitializer() {
		return new InitializingBean() {
			public void afterPropertiesSet() throws Exception {
				processEngineConfiguration
						.setUserEntityManager(new SpringSecurityUserManager(processEngineConfiguration,
								new MybatisUserDataManager(processEngineConfiguration), userManager));
				processEngineConfiguration.setGroupEntityManager(new SpringSecurityGroupManager(
						processEngineConfiguration, new MybatisGroupDataManager(processEngineConfiguration)));
			}
		};
	}
}
